/*
Auhtor      : Pratibh Prakash
Company     : Fujitsu America
Created Date: 17 Sep-2009
Modified    : 
Description : Test class for "OpportunityLineItemExtensionTest" controller .
*/
@isTest
private class OpportunityLineItemExtensionTest {

    static testMethod void testOpportunityItemExt() {
		//Preparing mock data
		Account testAccount = new Account(Name='Test Account');
		insert testAccount;
		Opportunity testOpp = new Opportunity(Name = 'Test Opportunity', AccountId = testAccount.Id, StageName = '4 - Negotiate', IM_Booked_Date__c = Date.Today(), closedate = Date.Today()+1);
		insert testOpp;
			
		//Retrieving standard pricebook
		Pricebook2 testStandardPriceBook = [select id from Pricebook2 where IsStandard = true];
		//Creating a Prooduct, PriceBookEntry for it and using these record to generate OpportunityLineItem record.
		Product2 testProd = new Product2(Name = 'Test Product', IsActive= true, CanUseRevenueSchedule = true, NumberOfRevenueInstallments=12, RevenueInstallmentPeriod='Monthly', RevenueScheduleType='Divide');
		insert testProd;
		PriceBookEntry testPriceBookEntry =  new PriceBookEntry(Product2Id = testProd.Id, Pricebook2Id = testStandardPriceBook.Id, UnitPrice = 1, IsActive = true, UseStandardPrice = false);
		insert testPriceBookEntry;
		
		//Creating OpportunityLineItem records	
		OpportunityLineItem oppProd = new OpportunityLineItem(Quantity = 12, PricebookEntryId = testPriceBookEntry.Id, OpportunityId = testOpp.Id, unitPrice = 1, Update_New_Revenue_Forecast__c =false );
		insert oppProd;
		OpportunityLineItem oppProd_withoutOppFcst = new OpportunityLineItem(Quantity = 12, PricebookEntryId = testPriceBookEntry.Id, OpportunityId = testOpp.Id, unitPrice = 1, Update_New_Revenue_Forecast__c =false );
		insert oppProd_withoutOppFcst;
		
		//Creating Opportunity Product Schedule record.
		OpportunityLineItemSchedule olis = new OpportunityLineItemSchedule(OpportunityLineItemId = oppProd.Id, Revenue=1, ScheduleDate= Date.Today(), Type='Revenue');
		insert olis;
			
		//Creating Opportunity Forecast record.
		IM_Opportunity_Forecast__c oppFcst = new IM_Opportunity_Forecast__c();
		oppFcst.OpportunityLIneItemScheduleId__c = olis.Id;
		oppFcst.Name = 'Test';
		oppFcst.Opportunity__c = testOpp.Id;
		oppFcst.Product__c = testProd.Id;
		oppFcst.OpportunityLineItemId__c = oppProd.Id;
		oppFcst.Revenue__c = 10;
		oppFcst.Schedule_Date__c = Date.Today();
		insert oppFcst;
		
		ApexPages.StandardController sc = new ApexPages.StandardController(oppProd);
		ApexPages.StandardController sc_withoutOppFcst = new ApexPages.StandardController(oppProd_withoutOppFcst);
		
		OpportunityLineItemExtension objOppLineItemExt = new OpportunityLineItemExtension(sc);
		OpportunityLineItemExtension objOppLineItemExt_withoutOppFcst = new OpportunityLineItemExtension(sc_withoutOppFcst);
		
		List<IM_Opportunity_Forecast__c> testOppFcstList = new List<IM_Opportunity_Forecast__c>();
		testOppFcstList.addAll(objOppLineItemExt.getOpportunityForecasts());
		PageReference testPage = objOppLineItemExt.UpdateForecast();
		
		//Calling setters and getters.
		objOppLineItemExt.setoppForecastFlag(true);
		objOppLineItemExt.setTempOppFcstList(testOppFcstList);
		testOppFcstList.clear();
		Boolean testFlag = objOppLineItemExt.getoppForecastFlag();
		testOppFcstList.addAll(objOppLineItemExt.getTempOppFcstList());
		
	}
}